package com.mengwen.backstage.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LiangYonghui
 * @date 2020/3/25 16:38
 * @description  有关二维码
 */
@Controller
public class CodeController {
    // 获二维码的url
    private String getCodeUrl = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://news.sina.com.cn/?openid=OPENID";

    // 将openid保留传送
    @RequestMapping("/send_openid")
    public String sendOpenid(HttpServletRequest request, Model model){
        String openid = request.getParameter("openid");
        model.addAttribute("openid",openid);
        return "share_style";
    }


    @RequestMapping("/getcode")
    public String getCode(HttpServletRequest request, Model model){
        String openid = request.getParameter("openid");
        String type = request.getParameter("type");
        System.out.println("type:" + type);
        if (type.equals("small_app")) {
            String codeUrl = getCodeUrl.replace("OPENID", openid);
            model.addAttribute("codeUrl",codeUrl);
            return "small_app";
        }else {
            System.out.println("pc端的");
            String codeUrl = getCodeUrl.replace("OPENID", openid);
            model.addAttribute("codeUrl",codeUrl);
            return "pc_code";

        }


    }
}
